package my.sc.controller;

import entity.Order;
import entity.Product;
import lombok.extern.java.Log;
import my.sc.openfeign.ProductFeign;
import my.sc.sercice.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author ：Q大侠
 * @date ：Created in 2022/11/17 21:45
 * @description：
 * @modified By：
 * @version:
 */
@Log
@RestController
@RequestMapping("/order")
public class OrderController3 {

    //必须创建并交与spring容器管理，这样才能被注入到相应的类属性上
    @Autowired
    private OrderService orderService;
    @Autowired
    private ProductFeign productFeign;
    @GetMapping("/saveOrder")
    public Order saveOrder(Long pid,Integer num){
        Order order=new Order();
        //用户得信息可以从登录后获取--Session  redis  jwt
        order.setUid(1);
        order.setUsername("玛卡巴卡");
        //为订单对象设置商品得信息
        order.setPid(pid);
        Product forObject = productFeign.getById(pid);
        order.setPname(forObject.getPname());
        order.setPprice(forObject.getPprice());
        order.setNumber(num);
        orderService.save(order);
        return order;
    }
    @GetMapping("aa")
    public String aa(){
        orderService.aa();
        return "aa操作!";
    }
    @GetMapping("bb")
    public String bb(){
        orderService.aa();
        return "bb操作!";
    }
}
